var wae_setobj = null;
var eventSender_obj = null;
var isfocus = true;
var msg_obj = null;
var simpleFile_obj = null;
var wae_httpobj = null;
var intent_obj = null;
var netManager_obj = null;
var apps_obj = null;
var simpleFile_obj = null;//sd卡文件




var set_id = sessionStorage.getItem( "set_iid");
sessionStorage.setItem( "set_iid", "");
if(!set_id)
	set_id = "focusId";


function $(str) { return document.getElementById(str)}


var m_waeErrorHandler = null;
var m_returnCallback = null;
function openMessage(msg){
	alert(msg);
}
//启动时间机制,气温

window.onWAEReady = function(){
	
	if(wae.can("tools.ErrorHandler")&&wae.can("tools.ErrorHandler")==true){
		m_waeErrorHandler = wae.create("tools.ErrorHandler");
	}
	
	//弹出框返回处理函数
	m_waeErrorHandler.onErrorHandlerResult = function(e){
		var _returnCode = e.arguments[0];
		if(_returnCode==0)
			return;
			
		if(m_returnCallback)
				eval("("+m_returnCallback+")");
	}
	
	if(!SERVER_URL||SERVER_URL==null){
		//var msg = "请输入服务器地址";
		//openMessage(msg);
		
	}

	
	eventSender_obj = wae.create("EventSender");
	if (eventSender_obj == null) {
		console.log("FAIL: create EventSender  object null!");
	}
	
	wae_setobj = wae.create("plugins.SettingsExpands");
	
	initPaw()
	showVersion();
	
	//VatataPublic.updatetime_Temperature($("weekId"),$("timeId"),$("temperatureId"),$("temperatureImgId"));
	//dateTimeInit();
}


//检查密码开启状态
function initPaw(){
	var protectVal = waeparams.getContentProviderPersistence("protect");	
	if(protectVal=="on"){
		VatataKeyMove.initVttKeymoveById($("revisePawId"));
		$("editpawTextId").style.display ="block";
		$("pawOnId").innerHTML="已开启";
		$("cancelProId").innerHTML="关闭";
		
	}else if(protectVal=="off"){
		VatataKeyMove.initVttKeymoveById($("cancelProId"));
		$("editpawTextId").style.display ="none";
		$("pawOnId").innerHTML="已关闭";	
		$("cancelProId").innerHTML="开启";	
	}
}


//点击修改密码
function revisePaw(){
	$("reviseDivId").style.display ="block";
	$("closePawId").style.display ="none";
	VatataKeyMove.initVttKeymoveById($("oldPawId"));

	
}


function  editpaw(id,str){
	var sear_stt = prompt(str);
	if(sear_stt){
		$(id).innerHTML = 	sear_stt;
	}	
}

//确认新密码
function savePaw(){
	var getoldPaw  =  waeparams.getContentProviderPersistence("myappspaw");
	var newPaw = $("newPawId").innerHTML;
	var renewPaw = $("renewPawId").innerHTML;
	var oldPaw = $("oldPawId").innerHTML;
	if(oldPaw!=getoldPaw){
		alert("原密码输入错误，请重新输入。");
		resetPaw();
	}else{
		if(newPaw!=renewPaw){
			alert("两次密码输入不一致，请重新输入。");
			resetPaw();	
		}else{
			waeparams.addContentProviderPersistenceWithAutoCommit("myappspaw" , renewPaw) ;	
			alert("密码修改成功，请牢记新密码。");
			$("reviseDivId").style.display ="none";
			resetPaw();
			VatataKeyMove.initVttKeymoveById($("revisePawId"));
		}
	}
}

//取消修改密码
function cancelPaw(){
	$("reviseDivId").style.display ="none";
	resetPaw();
	VatataKeyMove.initVttKeymoveById($("revisePawId"));	
		
}

function resetPaw(){
	$("oldPawId").innerHTML="请输入原密码";
	$("newPawId").innerHTML = "请输入新密码";
	$("renewPawId").innerHTML = "确认新密码";	
}

function reClose(){
	$("closeProPawId").innerHTML="请输入密码";
	
}

//开启密码
function resetOpenPaw(){
	$("openproPawId").innerHTML = "请输入新密码";
	$("reopenPawId").innerHTML = "确认新密码";	
}

//关闭/打开保护功能
function doProtect(){
	var protectVal = waeparams.getContentProviderPersistence("protect");	
	if(protectVal=="on"){
		cancelProtect()
	}else if(protectVal=="off"){
		openProtect();
	}	
}



//关闭密码
function cancelProtect(){
	$("reviseDivId").style.display ="none";
	$("closePawId").style.display ="block";
	VatataKeyMove.initVttKeymoveById($("closeProPawId"));
	
	
}

//确认关闭密码
function closePro(){
	var getoldPaw  =  waeparams.getContentProviderPersistence("myappspaw");
	var inputPaw = $("closeProPawId").innerHTML;
	
	if(getoldPaw!=inputPaw){
		alert("密码输入错误，请重新输入。")	;
		reClose()
	}else{
		waeparams.addContentProviderPersistenceWithAutoCommit("protect" , "off") ;	
		alert("家长保护已关闭。")	;
		$("closePawId").style.display ="none";
		initPaw();
		reClose();
		VatataKeyMove.initVttKeymoveById($("cancelProId"));
	}	
}
//取消关闭密码
function canClosePro(){
	
	$("closePawId").style.display ="none";
	reClose();
	VatataKeyMove.initVttKeymoveById($("revisePawId"));	
}

//开启密码
function openProtect(){
	$("reviseDivId").style.display ="none";
	$("openPawId").style.display ="block";
	VatataKeyMove.initVttKeymoveById($("openproPawId"));
		
}

//开启新密码
function saveOpenPaw(){
	
	var newPaw = $("openproPawId").innerHTML;
	var renewPaw = $("reopenPawId").innerHTML;
	if(newPaw!=renewPaw){
		alert("两次密码输入不一致，请重新输入。");
		resetOpenPaw();	
	}else{
		waeparams.addContentProviderPersistenceWithAutoCommit("myappspaw" , renewPaw) ;	
		waeparams.addContentProviderPersistenceWithAutoCommit("protect" , "on") ;
		alert("密码开启成功，请牢记密码。");
		$("openPawId").style.display ="none";
		resetOpenPaw();
		initPaw();
	}
	
}

//取消开启密码
function cancelOpenPaw(){
	$("openPawId").style.display ="none";
	resetOpenPaw();
	VatataKeyMove.initVttKeymoveById($("cancelProId"));	
		
}


window.onbeforeunload = function(){
	VatataKeyMove.clearAllVttKey();
}




/**
 * 显示版本号
 */

var application_obj = null;
//版本
function showVersion(){
	try{
	if(!application_obj){
		application_obj = wae.create("Application");
	}
	
	document.getElementById('versionName').innerText = 'ver '+application_obj.versionName() + '.' + HTML_PAGE_VERSION;
	}catch(e){}
}

